#lang racket


(require "../global.rkt")

(require (prefix-in cons: "constructor.rkt"))


(provide 
 ; primitives
 arc
 elliptical-arc
 circle
 donut
 ellipse
 helix-2d
 line
 ngon
 nurbs-curve
 nurbs-surface
 rectangle
 spline
 star
 ;text
 
 box
 cone
 cone-frustrum
 cylinder
 pipe
 sphere
 
 ; operations
 extrude
 intersect
 loft
 move
 offset
 rotate
 scale
 subtract
 union
 
 ; lang
 on-left
 on-right
 on-x
 on-front
 on-back
 on-y
 on-top
 on-bottom
 on-z)


; primitives

(define-syntax define-constructor-cache
  (syntax-rules ()
    ((_ (name cons-name))
     (define name
       (let ((cache (make-hash)))
         (λ args
           (if rosetta.cache?
               (if (hash-has-key? cache args)
                   (hash-ref cache args)
                   (let ((node (apply cons-name args)))
                     (hash-set! cache args node)
                     node))
               (apply cons-name args))))))))

(define-constructor-cache (arc cons:arc))
(define-constructor-cache (elliptical-arc cons:elliptical-arc))
(define-constructor-cache (circle cons:circle))
(define-constructor-cache (donut cons:donut))
(define-constructor-cache (ellipse cons:ellipse))
(define-constructor-cache (helix-2d cons:helix-2d))
(define-constructor-cache (line cons:line))
(define-constructor-cache (ngon cons:ngon))
(define-constructor-cache (nurbs-curve cons:nurbs-curve))
(define-constructor-cache (nurbs-surface cons:nurbs-surface))
(define-constructor-cache (rectangle cons:rectangle))
(define-constructor-cache (spline cons:spline))
(define-constructor-cache (star cons:star))

;(define-constructor-cache (text text)
;  (make-text-node text))

(define-constructor-cache (box cons:box))
(define-constructor-cache (cone cons:cone))
(define-constructor-cache (cone-frustrum cons:cone-frustrum))
(define-constructor-cache (cylinder cons:cylinder))

;(define-constructor-cache (elliptical-cone x-radius y-radius height))
;(define-constructor-cache (gengon width sides fillet-width height))
;(define-constructor-cache (helix-3d base-radius top-radius section-radius turns turn-height direction))
;(define-constructor-cache (mesh vertices faces))
;(define-constructor-cache (paraboloid radius height))

(define-constructor-cache (pipe cons:pipe))

;(define-constructor-cache (platonic-solids width sides))
;(define-constructor-cache (pyramid width sides height))

(define-constructor-cache (sphere cons:sphere))


; operations

;(define-constructor-cache (spindle radius height))
;(define-constructor-cache (superellipsoid width length height))
;(define-constructor-cache (torus base-radius section-radius))
;(define-constructor-cache (truncated-icosahedron width))
;(define-constructor-cache (wedge width height))

(define-constructor-cache (extrude cons:extrude))

;(define-constructor-cache (guide-loft guide shapes))

(define-constructor-cache (intersect cons:intersect))

;(define-constructor-cache (lattice shape))

(define-constructor-cache (loft cons:loft))

;(define-constructor-cache (mirror plane shape))

(define-constructor-cache (move cons:move))
(define-constructor-cache (offset cons:offset))

;(define-constructor-cache (path-loft path shapes))
;(define-constructor-cache (revolve axis shape))

(define-constructor-cache (rotate cons:rotate))
(define-constructor-cache (scale cons:scale))

;(define-constructor-cache (slice plane shape))

(define-constructor-cache (subtract cons:subtract))

;(define-constructor-cache (sweep path shape))
;(define-constructor-cache (thicken length shape))

(define-constructor-cache (union cons:union))


; lang

(define-constructor-cache (on-left cons:on-left))
(define-constructor-cache (on-right cons:on-right))
(define-constructor-cache (on-x cons:on-x))
(define-constructor-cache (on-front cons:on-front))
(define-constructor-cache (on-back cons:on-back))
(define-constructor-cache (on-y cons:on-y))
(define-constructor-cache (on-top cons:on-top))
(define-constructor-cache (on-bottom cons:on-bottom))
(define-constructor-cache (on-z cons:on-z))